<template>
  <div class="header">
    <div class="inner fn-clearfix">
      <a href="javascript:void(0);" class="logo-name fn-fl">
        <h3 class="title">{{ wpzswTitle }}</h3>
      </a>
      <div class="login-info fn-fr" v-if="isPrivacyPage">
        <router-link class="index-link" :to="{ path: '/' }">
          <img src="../assets/images/icon_home.png" alt="" />
          <span>首页</span>
        </router-link>
        <div class="login-over" v-if="userName && !isShow">
          <img :src="require('../assets/images/head-portrait.png')" alt="" />
          <span class="hello">你好，{{ userName }}</span>
          <div class="drop-down">
            <div class="drop-logout">
              <span class="el-dropdown-link">
                注销<i
                  class="el-icon-arrow-down el-icon--right"
                  style="color: #999"
                ></i>
              </span>
              <div class="drop-item">
                <span @click="logout">注销</span>
                <span @click="signout">退出</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import localDb from "../utils/localDb";
export default {
  name: "Header",
  props: {
    isShow: {
      type: Boolean,
      default: true,
    },
    isPrivacyPage: {
      type: Boolean,
      default: true,
    },
    // isFromDelay: {
    //   type: Boolean,
    //   default: false,
    // },
  },
  data() {
    return {};
  },
  computed: {
    userName() {
      return this.$store.state.user;
    },
    wpzswTitle() {
      return this.$store.state.wpzswTitle;
    },
    isDelayApply() {
      return this.$store.state.isDelayApply;
    },
    verify() {
      return this.$store.state.verify;
    },
  },
  methods: {
    signout() {
      // localDb.clear("3");
      // if (isFromDelay) {
      //   this.$store.commit("SETDELAYAPPLY", true);
      // }
      this.$confirm("确定要退出账号登录吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$store.commit("SETUSER", "");
          this.$store.commit("SETTOKEN", "");
          this.$store.commit("SETSTULIST", "");
          this.$router.push({ path: "/zmkm" });
        })
        .catch(() => {});
    },
    logout() {
      if (this.verify.res == -1) {
        this.$message.error(this.verify.msg);
        return false;
      }
      this.$confirm(
        "确定要注销账户吗？注销后将删除你的账号（包括基本信息、图片、报名记录），账号也无法登录，但可以重新注册。（注销点击“确定”，不注销点击“取消”）",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        if (this.isDelayApply) {
          this.$fetch("/api/Student/PersonDelayLogOut", {}, "post").then(
            (data) => {
              if (data.res == 0) {
                this.$router.push({ path: "/" });
              } else {
                this.$message.error(data.msg);
              }
            }
          );
        } else {
          this.$fetch("/api/Student/LogOut", {}, "post").then((data) => {
            if (data.res == 0) {
              this.$router.push({ path: "/" });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.header {
  min-width: 1200px;
  background: #fff;
  box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.06);
  .inner {
    height: 80px;
  }
  .logo-name {
    display: block;
    line-height: 80px;
    color: #fff;
    font-size: 32px;
    font-weight: normal;
    text-decoration: none;
    .title {
      padding-left: 14px;
      color: #000;
      font-size: 32px;
      font-weight: normal;
    }
  }
  h3 {
    font-size: 32px;
    color: #000;
    line-height: 80px;
  }
  .login-info {
    position: absolute;
    right: 0;
    top: 0;
    height: 80px;
    line-height: 80px;
    color: #333;
    a {
      padding: 0 10px;
      color: #333;
      text-decoration: none;
      outline: none;
      &.index-link {
        color: #0195ff;
        img {
          vertical-align: middle;
          margin-top: -5px;
          margin-right: 10px;
        }
        span {
          font-size: 14px;
        }
      }
    }
    .login-over {
      img {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        vertical-align: middle;
        margin-left: 10px;
      }
      .hello {
        color: #999;
        font-size: 14px;
      }
      .drop-down {
        float: right;
        position: relative;
        .drop-logout {
          height: 40px;
          display: inline-block;
          line-height: 40px;
          font-size: 14px;
          position: relative;
          color: #222;
          cursor: pointer;
          .drop-item {
            display: none;
            width: 68px;
            height: 88px;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2);
            line-height: 32px;
            text-align: center;
            z-index: 999;
            position: absolute;
            left: 0;
            top: 38px;
            font-size: 14px;
            span {
              width: 100%;
              display: inline-block;
              margin-top: 5px;
              line-height: 39px;
              color: #222;
              &:hover {
                cursor: pointer;
                background-color: #ecf5ff;
                color: #0195ff;
              }
            }
            &::after {
              content: "";
              border-right: 6px solid transparent;
              border-left: 6px solid transparent;
              border-bottom: 6px solid #fff;
              position: absolute;
              left: 30px;
              top: -4px;
            }
          }
          &:hover .drop-item {
            display: block;
          }
        }
      }
    }
  }
  .login-before {
    display: inline-block;
  }
  .login-over {
    display: inline-block;
    span {
      padding: 0 10px;
    }
  }
}
</style>
<style lang="scss">
.el-message-box__wrapper {
  .el-message-box {
    padding-bottom: 20px;
    .el-message-box__header {
      height: 40px;
      background-color: #fafafa;
      border-bottom: 1px solid #eee;
      .el-message-box__title {
        font-size: 16px;
        color: #333;
        line-height: 10px;
      }
      .el-message-box__headerbtn {
        top: 11px;
      }
    }
    .el-message-box__content {
      padding: 20px 20px;
      .el-message-box__container {
        .el-message-box__message {
          font-weight: bold;
          color: #222;
          font-size: 16px;
          padding-left: 45px;
        }
      }
    }
    .el-message-box__btns {
      padding: 5px 20px 0;
      .el-button {
        width: 60px;
        font-size: 14px;
        height: 32px;
        line-height: 16px;
        border-radius: 4px;
        padding: 0;
        &:first-child {
          color: #fff;
          background-color: #0195ff;
          border-color: #0195ff;
        }
        &:last-child {
          background-color: #fff;
          color: #000;
          border-color: #ccc;
        }
      }
    }
  }
}
</style>
